import Request from '../static/js/request.js';
let request = new Request().http;

import UploadFile from '../static/js/upload.js';
let uploadFile = new UploadFile().http;

export default {
	logined: function(upJson) { //用户登录
		return request({
			url: "/api/auth/login", 
			data: upJson,
			bMsg: "登录中",
			methods: "POST",
			type: 1
		})
	},
	getWxUserinfo: function(upJson) { //微信用户授权
		return request({
			url: "/api/auth/weapi",
			data: upJson,
			bMsg: "登录中",
			methods: "POST",
			type: 1
		})
	},
	getUserInfo: function(upJson) { //获取用户信息
		return request({
			url: "/api/info/info_user",
			data: upJson,
			methods: "POST"
		})
	},
	editUserInfo: function(upJson) { //编辑用户信息
		return request({
			url: "/api/info/update_user",
			data: upJson,
			back: true,
			type: 3,
			eMsg: "修改成功",
			methods: "POST"
		})
	},
	addClient: function(upJson, type) { //增改商户
		if (type == 0) {
			return request({
				url: "/api/customer/create",
				data: upJson,
				back: true,
				type: 3,
				eMsg: "保存成功",
				methods: "POST"
			})
		} else {
			return request({
				url: "/api/customer/update",
				data: upJson,
				back: true,
				type: 3,
				eMsg: "修改成功",
				methods: "POST"
			})
		}
	},
	getClientTypeList: function(upJson) { //获取商户类型列表
		return request({
			url: "/api/common/customer_type",
			data: upJson,
			methods: "POST"
		})
	},
	getClientList: function(upJson) { //获取商户列表
		return request({
			url: "/api/customer/lists",
			data: upJson,
			methods: "POST"
		})
	},
	getClientLabel: function(upJson) { //获取商户标签列表
		return request({
			url: "/api/customer/customer_tags",
			data: upJson,
			methods: "GET"
		})
	},
	getClientDetails: function(upJson, type) { //获取商户数据
		if (type == 0) { //商户详情
			return request({
				url: "/api/customer/details",
				data: upJson,
				methods: "POST"
			})
		} else if (type == 1) { //商户设备类别
			return request({
				url: "/api/customer/device_list",
				data: upJson,
				methods: "GET"
			})
		} else if (type == 2) { //商户派工列表
			return request({
				url: "/api/work/customer_work_lists",
				data: upJson,
				methods: "GET"
			})
		} else if (type == 3) { //商户拜访列表
			return request({
				url: "/api/customer/visit_list",
				data: upJson,
				methods: "GET"
			})
		} else if (type == 4) { //商户联系人列表
			return request({
				url: "/api/customer/contact_list",
				data: upJson,
				methods: "GET"
			})
		}else if(type == 5){ // 商户订单列表
			return request({
				url:"/api/order/order_lists",
				data:upJson,
				methods:"POST"
			})
		}
	},
	// 删除客户联系人
	removeContact:function(upJson){
		return request({
			url: "/api/customer/remove_contact",
			data: upJson,
			methods: "POST"
		})
	},
	getVisitSign: function(upJson) { //拜访签到
		return request({
			url: "/api/customer/visit_sign",
			data: upJson,
			methods: "POST",
			// back: true,
			// type: 3,
			// eMsg: "拜访成功"
		})
	},
	//获取区域列表
	getRegionList: (upJson) => {
		return request({
			url: "/api/customer/customer_area",
			methods: "GET"
		})
	},
	// 获取营业面积列表
	getBizAreaList:(upJson)=>{
		return request({
			url: "/api/customer/customer_biz_area",
			methods: "GET"
		})
	},
	getCustomerList: function(upJson) { //获取客户列表
		return request({
			url: "/api/customer/search_lists",
			data: upJson,
			methods: "GET"
		})
	},
	getClientEquipmentDetail: function(upJson) { //客户设备详情
		return request({
			url: "/api/customer/device_detail",
			data: upJson,
			methods: "GET"
		})
	},
	getTransferCustomer: function(upJson) { // 转交客户
		return request({
			url: "/api/customer/transfer_customer",
			data: upJson, // sale_user_id contact_user_id   user_id customer_id
			methods: "POST",
			type:4
		})
	},
	getDeviceRecord: function(upJson) { //维修保养记录
		return request({
			url: "/api/customer/device_record",
			data: upJson,
			methods: "GET"
		})
	},
	addClientEquipment: function(upJson) { //客户新增设备
		return request({
			url: "/api/customer/device_create",
			data: upJson,
			back: true,
			type: 3,
			methods: "POST"
		})
	},
	editClientEquipment: function(upJson) { //客户编辑设备
		return request({
			url: "/api/customer/device_update",
			data: upJson,
			back: true,
			type: 3,
			methods: "POST"
		})
	},
	addClientPhone: function(upJson) { //客户新增联系人
		return request({
			url: "/api/customer/update_contact",
			data: upJson,
			back: true,
			type: 3,
			methods: "POST"
		})
	},
	getClientVisitType: function(upJson) { //获取拜访类型
		return request({
			url: "/api/customer/visit_type",
			data: upJson,
			methods: "GET"
		})
	},
	addClientVisit: function(upJson, type) { //客户新增拜访
		if (type == 0) {
			return request({
				url: "/api/customer/visit_detail",
				data: upJson,
				methods: "GET"
			})
		} else if (type == 1) {
			return request({
				url: "/api/customer/update_visit",
				data: upJson,
				methods: "POST",
				back: true,
				type: 3,
				eMsg: "修改成功"
			})
		} else if (type == 2) {
			return request({
				url: "/api/customer/visit_answer",
				data: upJson,
				methods: "POST",
				back: true,
				type: 3,
				eMsg: "留言成功"
			})
		} else if (type == 4) {
			return request({
				url: "/api/customer/visit_del",
				data: upJson,
				methods: "POST"
			})
		} else if (type == 5) {
			return request({
				url: "/api/customer/visit_customer",
				data: upJson,
				back: true,
				type: 3,
				methods: "POST"
			})
		} else if (type == 6) {
			return request({
				url: "/api/customer/answer_list",
				data: upJson,
				methods: "POST"
			})
		}
	},
	//客户跟踪状态
	getTrackStatusList: () => {
		return request({ 
			url: "/api/customer/status_list",
			methods: "GET"
		})
	},
	getRepeatCustomer: function(upJson) { //查重
		return request({
			url: "/api/customer/repeat_customer",
			data: upJson,
			methods: "GET"
		})
	},




	getWorkList: function(upJson, type) { //获取工单列表
		return request({
			url: "/api/work/lists",
			data: upJson,
			methods: "GET"
		})
	},
	getWorkDetail: function(upJson) { // 获取工单详情
		return request({
			url: "/api/work/details",
			data: upJson,
			methods: "GET"
		})
	},
	getWorkType: function(upJson) { // 获取工单类型
		return request({
			url: "/api/work/work_type",
			data: upJson,
			methods: "GET"
		})
	},
	getWorkStatus: function(upJson) { // 获取工单状态
		return request({
			url: "/api/work/work_status",
			data: upJson,
			methods: "GET" 
		})
	},
	getServiceList: function() { // 获取服务列表
		return request({
			url: "/api/work/work_service",
			methods: "GET"
		})
	},
	getWorkSign: function(upJson) { // 工单签到
		return request({
			url: "/api/work/sign",
			data: upJson,
			methods: "POST"
		})
	},
	getWorkCreact: function(upJson, resMsg) { // 派单
		return request({
			url: '/api/work/work_create',
			data: upJson,
			back: true,
			type: 3,
			eMsg: resMsg,
			methods: "POST"
		})
	},

	getWorkComplete: function(upJson) { // 完成工单
		return request({
			url: "/api/work/complete",
			data: upJson,
			back: true,
			type: 7,
			eMsg: '完成工单',
			methods: "POST"
		})
	},
	changeWorkInfo: function(upJson) { // 工单审核通过
		return request({
			url: "/api/work/work_update",
			data: upJson,
			back: true,
			type: 7,
			eMsg: '修改成功',
			methods: "POST"
		})
	},
	giveUpWork: function(upJson) {
		return request({
			url: "/api/work/un_complete",
			data: upJson,
			type: 7,
			eMsg: '弃用成功',
			methods: "POST"
		})
	},
	workEgis: function(upJson) { // 工单审核通过
		return request({
			url: "/api/work/review",
			data: upJson,
			back: true,
			type: 7,
			eMsg: '审核完成',
			methods: "POST"
		})
	},
	getCreatDesc: function(upJson) { // 添加描述
		return request({
			url: "/api/work/create_desc",
			data: upJson,
			type: 3,
			eMsg: '添加描述成功',
			methods: "POST"
		})
	},
	getUpdateDesc: function(upJson) { // 添加描述
		return request({
			url: "/api/work/update_desc",
			data: upJson,
			type: 3,
			eMsg: '修改描述成功',
			methods: "POST"
		})
	},

	//获取订单收款二维码
	getPayQRCode: (upJson) => {
		return request({
			url: "/api/order/order_payment",
			data: upJson,
			methods: "POST"
		})
	},
	//线下收款
	collectMoney: (upJson) => {
		return request({
			url: "/api/order/order_payment_offline",
			data: upJson,
			methods: "POST"
		})
	},
	getOrderStatus: function(upJson) { // 订单状态
		return request({
			url: "/api/order/order_status",
			data: upJson,
			methods: "GET"
		})
	},
	getOrderAudit: function(upJson) { //审核成交
		return request({
			url: "/api/order/order_audit",
			data: upJson,
			methods: "GET"
		})
	},
	getStatistics: function(upJson, type) { //获取订单统计
		return request({
			url: "/api/order/order_statistics",
			data: upJson,
			methods: "GET"
		})
	},
	getOrderList: function(upJson, type) { //获取订单列表
		return request({
			url: "/api/order/order_lists",
			data: upJson,
			methods: "POST"
		})
	},
	getCustomerOrderList:function(upJson){ // 获取客户订单列表
		return request({
			url: "/api/order/related_order_list",
			data: upJson,
			methods: "POST"
		})
	},
	getCustomerOrderStatistics:function(upJson){ // 获取客户订单统计
		return request({
			url: "",
			data: upJson,
			methods: "GET"
		})
	},
	getRelationOrderList: function(upJson, type) { //获取关联列表
		return request({
			url: "/api/order/related_order_list",
			data: upJson,
			methods: "GET"
		})
	},
	getOrderClass: function(upJson, type) { //获取订单类别
		return request({
			url: "/api/order/order_class",
			data: upJson,
			methods: "GET"
		})
	},
	getOrderPayMethods: function(upJson, type) { //获取订单收款方式
		return request({
			url: "/api/order/payment_method",
			data: upJson,
			methods: "GET"
		})
	},
	getOrderInvoiceType: function(upJson, type) { //获取发票类型
		return request({
			url: "/api/order/invoice_type",
			data: upJson,
			methods: "GET"
		})
	},
	addOrder: function(upJson) { //新增订单
		return request({
			url: "/api/order/create_order",
			data: upJson,
			methods: "POST",
			back: true,
			type: 3,
			eMsg: "新增成功"
		})
	},
	editOrder:function(upJson){ // 修改订单
		return request({
			url: "/api/order/edit",
			data: upJson,
			eMsg: "修改成功",
			methods: "POST"
		})
	},
	getOrderDetail: function(upJson) { // 获取订单详情
		return request({
			url: "/api/order/order_detail",
			data: upJson,
			methods: "GET"
		})
	},
	getOrderSchedule: function(upJson) { // 订单进度
		return request({
			url: "/api/order/order_schedule",
			data: upJson,
			methods: "GET"
		})
	},
	editSchedule: function(upJson) { //修改进度
		return request({
			url: "/api/order/edit_schedule",
			data: upJson,
			eMsg: "修改成功",
			methods: "GET"
		})
	},
	addProduct: function(upJson) { //创建产品
		return request({
			url: "/api/product/create",
			data: upJson,
			methods: "POST",
			back: true,
			type: 3,
			eMsg: "新增成功"
		})
	},
	partsPayQRCode: function(upJson) { // 配件收款二维码
		return request({
			url: "/api/product/parts_pay",
			data: upJson,
			methods: "POST"
		}) 
	},
	getProductLibrary: function(upJson, type) { //获取产品仓库
		return request({
			url: "/api/common/warehouse",

			data: upJson,
			methods: "POST"
		})
	},
	getProductWarehouse: (upJson) => { //获取产品有库存的仓库
		return request({
			url: "/api/product/warehouse",
			data: upJson,
			methods: "GET"
		})
	},
	getProductType: function(upJson, type) { //获取产品类型
		return request({
			url: "/api/common/product_type",
			data: upJson,
			methods: "POST"
		})
	},
	getProductList: function(upJson, type) { //获取产品列表
		return request({
			url: "/api/product/lists",
			data: upJson,
			methods: "POST"
		})
	},
	getProductInfo: function(upJson, type) { //获取产品详情
		return request({
			url: "/api/product/details",
			data: upJson,
			methods: "POST"
		})
	},
	getProductIntoList: function(upJson, type) { //获取产品出入库状态列表 0入库状态 1出库状态
		return request({
			url: "/api/product/order_type",
			data: upJson,
			methods: "GET"
		})
	},
	getProductMoveList: function(upJson, type) { //获取产品调拨状态列表
		return request({
			url: "/api/product/get_change",
			data: upJson,
			methods: "POST"
		})
	},
	getProductStock: function(upJson, type) { //获取产品库存信息
		return request({
			url: "/api/product/stock",
			data: upJson,
			methods: "GET"
		})
	},
	getProductOut: function(upJson, type) { //获取产品销售应发货
		return request({
			url: "/api/product/sale_shipped",
			data: upJson,
			methods: "GET"
		})
	},
	getProductClass: function(upJson, type) { //获取产品类别
		return request({
			url: "/api/order/order_class",
			data: upJson,
			methods: "GET"
		})
	},
	moveProduct: function(upJson, type) { //产品调拨
		return request({
			url: "/api/product/change_warehouse",
			data: upJson,
			methods: "POST",
			back: true,
			type: 3
		})
	},
	changeProductPrice: function(upJson, type) { //修改产品价格
		return request({
			url: "/api/product/update_price",
			data: upJson,
			methods: "POST",
			back: true,
			type: 3
		})
	},
	deleteProduct: function(upJson, type) { //删除产品
		return request({
			url: "/api/product/remove",
			data: upJson,
			methods: "POST"
		})
	},
	addPutLibrary: function(upJson, type) { //产品出库
		return request({
			url: "/api/product/product_put",
			data: upJson,
			methods: "POST",
			back: true,
			type: 3
		})
	},
	addIntoLibrary: function(upJson, type) { //产品入库
		return request({
			url: "/api/product/product_into",
			data: upJson,
			methods: "POST",
			back: true,
			type: 3
		})
	},
	getSupplierList: function(upJson, type) { //获取供应商列表
		return request({
			url: "/api/product/supplier_list",
			data: upJson,
			methods: "GET"
		})
	},
	getLibraryList: function(upJson, type) { //获取资料库列表
		return request({
			url: "/api/common/material",
			data: upJson,
			methods: "POST"
		})
	},
	getLibraryInfo: function(upJson, type) { //获取资料库详情
		return request({
			url: "/api/common/material_details",
			data: upJson,
			methods: "POST"
		})
	},
	getAccessoriesLibrary: function(upJson, type) { //获取配件仓库列表
		return request({
			url: "/api/product/parts_list_all",
			data: upJson,
			methods: "GET"
		})
	},
	getAccessoriesType2: function(upJson, type) { //获取附件类型
		return request({
			url: "/api/product/attach_type",
			data: upJson,
			methods: "GET"
		})
	},
	getAccessoriesType: function(upJson, type) { //获取配件类型
		return request({
			url: "/api/product/parts_type",
			data: upJson,
			methods: "POST"
		})
	},
	getAccessoriesList: function(upJson, type) { //获取配件列表
		return request({
			url: "/api/product/parts_list",
			data: upJson,
			methods: "GET"
		})
	},
	getMyAccessoriesList: function(upJson, type) { //获取我的配件列表/附件列表
		return request({
			url: "/api/product/my_parts",
			data: upJson,
			methods: "GET"
		})
	},
	getMyAccessoriesReceiveList:function(upJson){ // 获取配件领取明细列表
		return request({
			url: "/api/product/parts_receive_lists",
			data: upJson,
			methods: "GET"
		})
	},
	partsRefund:function(upJson){ // 配件退还
		return request({
			url: "/api/product/parts_refund",
			data: upJson,
			methods: "POST",
			back: true,
			type: 3,
			eMsg: "退还成功"
		})
	},
	getAccessoriesInfo: function(upJson, type) { //获取配件详情
		return request({
			url: "/api/product/parts_detail",
			data: upJson,
			methods: "GET"
		})
	},
	drawAccessories: function(upJson, type) { //领取配件
		return request({
			url: "/api/product/receive_parts",
			data: upJson,
			methods: "POST",
			back: true,
			type: 3,
			bMsg: "领取中"
		})
	},
	freeService: function(upJson, type) { //领取配件
		return request({
			url: "/api/product/free_service",
			data: upJson,
			methods: "POST",
			type: 3,
			bMsg: "提交中",
			eMsg: "提交成功"
		})
	},



	getReturnList: function(upJson, type) { //获取退换货列表
		return request({
			url: "/api/order/relate_list",
			data: upJson,
			methods: "GET"
		})
	},
	addReturn: function(upJson, type) { //新增退换货
		return request({
			url: "/api/order/relate_create",
			data: upJson,
			methods: "POST",
			back: true,
			type: 3,
			bMsg: "提交中"
		})
	},
	auditReturn: function(upJson, type) { //退换货审核
		return request({
			url: "/api/order/relate_audit",
			data: upJson,
			methods: "POST",
			back: true,
			type: 3,
			bMsg: "提交中"
		})
	},
	approveReturn:function(upJson){ // 退换货审批
		return request({
			url: "/api/order/relate_approval",
			data: upJson,
			methods: "POST",
			back: true,
			type: 3,
			bMsg: "提交中"
		})
	},
	getReturnInfo: function(upJson, type) { //获取退换货列表
		return request({
			url: "/api/order/relate_detail",
			data: upJson,
			methods: "GET"
		})
	},



	getFinanceList: function(upJson, type) { //获取财务列表
		return request({
			url: "/api/order/finance",
			data: upJson,
			methods: "GET"
		})
	},



	getBranchList: function(upJson) { //获取部门列表
		return request({
			url: "/api/common/branch_list",
			data: upJson,
			methods: "POST"
		})
	},
	getUserList: function(upJson) { //获取部门人员列表
		return request({
			url: "/api/user/lists",
			data: upJson,
			methods: "GET"
		})
	},
	getChatList:function(upJson,type){ // 获取统计数据列表

		if (type == 0) {  // 客户分类统计数据
			return request({
				url: "/api/Statistics/customer_statistics",
				data: upJson, 
				methods: "GET"
			})
		} else if( type == 1){ // 客户新增统计数据
			return request({
				url: "/api/Statistics/customer_add_statistics",
				data: upJson,
				methods: "GET"
			})	
		} else if( type == 2){ //  拜访计划统计
			return request({
				url: "/api/statistics/visit_statistics",
				data: upJson,
				methods: "GET"
			})	
		} else if( type ==3 ){ // 销售汇总
			return request({
				url: "/api/Statistics/sale_count",
				data: upJson,
				methods: "GET"
			})	
		} else if( type == 4){ // 销售走势统计
			return request({
				url: "/api/statistics/sale_statistics",
				data: upJson,
				methods: "GET"
			})	
		} else if( type ==5){ // 派工调度总览 -- 处理数据
			return request({
				url: "/api/statistics/work_statistics",
				data: upJson,
				methods: "GET"
			})
		} else if( type == 6){ // 派工调度总览图表
			return request({
				url: "/api/Statistics/work_chart_statistics",
				data: upJson,
				methods: "GET"
			})
		}
		
	},
	uploadFile: function(upJson) { //文件上传
		return uploadFile({
			url: "/api/common/upload",
			data: upJson
		})
	},
	getTimeString: function(time) { //时间转时间戳
		if (time.length == 10) {
			time += " 00:00:00";
		}
		time = time.split("-");
		time.length == 2 ? time = time[0] : time = time[0] + '/' + time[1] + '/' + time[2];
		return Date.parse(new Date(time)) / 1000
	},
	getNowTime: function() { //获取当前时间
		let time = new Date();
		let y = time.getFullYear();
		let m = time.getMonth() < 9 ? "0" + (time.getMonth() + 1) : time.getMonth() + 1
		let d = time.getDate() < 10 ? "0" + time.getDate() : time.getDate()
		return y + "-" + m + "-" + d
	},
	prompt: function(title) {
		uni.showToast({
			title,
			icon: "none"
		})
	}
}
